var templateParams = {
    tableTheads:["测试集名称", "测试用例", "创建时间", "创建人","备注", "操作"],
    btnTools:[{
        type:"primary",
        size:"M",
        id:"add-object",
        iconFont:"&#xe600;",
        name:"添加测试集"
    },{
        type:"danger",
        size:"M",
        id:"batch-op",
        iconFont:"&#xe6bf;",
        name:"批量操作"
    }],
    formControls:[{
        edit:true,
        label:"ID",
        objText:"idText",
        input:[{
            hidden:true,
            name:"id"
        }]
    },
        {
            required:true,
            label:"测试集名称",
            input:[{
                name:"set_name"
            }]
        },
        // {
        //     required:true,
        //     label:"并发执行",
        //     select:[{
        //         name:"if_parallel",
        //         option:function(){
        //             let options = [];
        //             $.each(GLOBAL_PARAM.CUSTOM_JUDGE_TYPE, function(i, n){
        //                 options.push({
        //                     value: i, text:n
        //                 });
        //             });
        //             return options;
        //         }()
        //     }]
        // },
        {
            label:"备注",
            textarea:[{
                name:"mark"
            }]
        }
    ]};

var columnsSetting = [
    {
        "data":null,
        "render":function(data, type, full, meta){
            return checkboxHmtl(data.set_name, data.id, "selectCaseSet");
        }},
    {"data":"id"},
    ellipsisData("set_name"),
    {
        "data":"case_count",
        "render":function(data, type, full, meta){
            var context =
                [{
                    type:"default",
                    size:"M",
                    markClass:"show-set-case",
                    name:data || 0
                }];
            return btnTextTemplate(context);
        }
    },
    ellipsisData("create_time"),
    ellipsisData("creator_name"),
    longTextData("mark", "set_name", "备注信息"),
    {
        "data":null,
        "render":function(data, type, full, meta){
            var context = [{
                title:"编辑",
                markClass:"object-edit",
                iconFont:"&#xe6df;"
            },{
                title:"删除",
                markClass:"object-del",
                iconFont:"&#xe6e2;"
            }];
            return btnIconTemplate(context);
        }
    }];

var eventList = {
    "#add-object":function(){
        publish.renderParams.editPage.modeFlag = 0;
        layer_show("添加测试集", editHtml, editPageWidth, editPageHeight.add, 1);
        publish.init();
    },
    "#batch-op":function(){
        layer.confirm(
            '请选择你需要进行的批量操作:',
            {
                title:'批量操作',
                btn:['删除', '取消'],
                shadeClose:true,
            },function(index){
                layer.close(index);
                batchOp($(".selectCaseSet:checked"), REQUEST_URL.WEB_CASE_SET.delSet, "删除", null, "id");
            },function(index){
                layer.close(index);
            });
    },
    ".object-edit":function(){
        var data = table.row( $(this).parents('tr') ).data();
        publish.renderParams.editPage.modeFlag = 1;
        publish.renderParams.editPage.objId = data.id;
        publish.renderParams.editPage.currentObj = data;
        layer_show("编辑测试集信息", editHtml, editPageWidth, editPageHeight.edit, 1);
        publish.init();
    },
    ".object-del":function(){
        var data = table.row( $(this).parents('tr') ).data();
        opObj("确认要删除此测试集吗？", REQUEST_URL.WEB_CASE_SET.delSet, {id:data.id}, this, "删除成功!");
    },
    //查询用例集下的用例列表
    ".show-set-case": function(){
        let data = table.row( $(this).parents('tr') ).data();
        layer_show(data.set_name + "-测试用例管理", "webSetCase.html?set_id=" + data.id, null, null, 2);
    }
};

var mySetting = {
    eventList:eventList,
    templateCallBack:function(df){
        df.resolve();
    },
    listPage:{
        listUrl:REQUEST_URL.WEB_CASE_SET.listSet,
        tableObj:".table-sort",
        columnsSetting:columnsSetting,
        columnsJson:[0, 7],
        dtOtherSetting:{serverSide:false}
    },
    editPage:{
        editUrl:REQUEST_URL.WEB_CASE_SET.editSet,
        getUrl:REQUEST_URL.WEB_CASE_SET.getSet,
        rules:{
            set_name:{
                required:true,
                minlength:2,
                maxlength:255
            }
        }
    },
    templateParams:templateParams
};

$(function(){
    publish.renderParams = $.extend(true,publish.renderParams,mySetting);
    publish.init();
});
